package com.todo.sight.application.service.impl;

import com.google.common.collect.Lists;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.sight.application.service.PoiTypeRelationService;
import com.todo.sight.application.convert.SightServiceConvert;
import com.todo.sight.application.entity.bo.PoiTypeRelationBO;
import com.todo.sight.infrastructure.entity.po.PoiTypeRelationPO;
import com.todo.sight.infrastructure.repository.PoiTypeRelationRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PoiTypeRelation)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 00:19:48
 */
@Slf4j
@Service("poiTypeRelationService")
public class PoiTypeRelationServiceImpl implements PoiTypeRelationService {

    @Resource
    private PoiTypeRelationRepository poiTypeRelationRepository;

    @Override
    public Boolean insertPoiTypeRelation(PoiTypeRelationBO poiTypeRelationBO) {
        if (poiTypeRelationBO == null) {
            log.warn("PoiTypeRelationService#insertPoiTypeRelation 新增poi类型关联失败，数据参数为空");
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        PoiTypeRelationPO poiTypeRelationPO = SightServiceConvert.convertToPoiTypeRelationPO(poiTypeRelationBO);
        return poiTypeRelationRepository.insertPoiTypeRelationPO(poiTypeRelationPO);
    }

    @Override
    public Boolean removePoiTypeRelationById(Long id) {
        if (id == null || id < 0) {
            log.warn("PoiTypeRelationService#removePoiTypeRelationById 删除poi类型关联失败，id为空");
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        return poiTypeRelationRepository.removePoiTypeRelationPOById(id);
    }

    @Override
    public List<PoiTypeRelationBO> queryPoiTypeRelationByPoiId(Long poiId) {
        if (poiId == null || poiId < 0) {
            log.warn("PoiTypeRelationService#queryPoiTypeRelationByPoiId 根据poiId查询关联列表失败，数据为空");
            return Lists.newArrayList();
        }
        List<PoiTypeRelationPO> poiTypeRelationPOS = poiTypeRelationRepository.queryPoiTypeRelationListByPoi(poiId);
        return SightServiceConvert.convertToPoiTypeRelationPOList(poiTypeRelationPOS);
    }

    @Override
    public List<PoiTypeRelationBO> queryPoiTypeRelationByBizId(Long businessId) {
        if (businessId == null || businessId < 0) {
            log.warn("PoiTypeRelationService#queryPoiTypeRelationByBizId 根据业务Id查询关联列表失败，数据为空");
            return Lists.newArrayList();
        }
        List<PoiTypeRelationPO> poiTypeRelationPOS = poiTypeRelationRepository.queryPoiTypeRelationListByBizId(businessId);
        return SightServiceConvert.convertToPoiTypeRelationPOList(poiTypeRelationPOS);
    }
}
